package com.dianping.cat.home.heavy.transform;

import com.dianping.cat.home.heavy.entity.HeavyCache;
import com.dianping.cat.home.heavy.entity.HeavyCall;
import com.dianping.cat.home.heavy.entity.HeavyReport;
import com.dianping.cat.home.heavy.entity.HeavySql;
import com.dianping.cat.home.heavy.entity.Service;
import com.dianping.cat.home.heavy.entity.Url;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.xml.sax.Attributes;







public class DefaultSaxMaker
  extends Object
  implements IMaker<Attributes>
{
  public HeavyCache buildHeavyCache(Attributes attributes) { return new HeavyCache(); }






  public HeavyCall buildHeavyCall(Attributes attributes) { return new HeavyCall(); }




  
  public HeavyReport buildHeavyReport(Attributes attributes) {
/*  38 */     String domain = attributes.getValue("domain");
/*  39 */     String startTime = attributes.getValue("startTime");
/*  40 */     String endTime = attributes.getValue("endTime");
/*  41 */     HeavyReport heavyReport = new HeavyReport(domain);

/*  43 */     if (startTime != null) {
/*  44 */       heavyReport.setStartTime(toDate(startTime, "yyyy-MM-dd HH:mm:ss", null));
    }
    
/*  47 */     if (endTime != null) {
/*  48 */       heavyReport.setEndTime(toDate(endTime, "yyyy-MM-dd HH:mm:ss", null));
    }
    
/*  51 */     return heavyReport;
  }


  
/*  56 */   public HeavySql buildHeavySql(Attributes attributes) { return new HeavySql(); }




  
  public Service buildService(Attributes attributes) {
/*  63 */     String domain = attributes.getValue("domain");
/*  64 */     String name = attributes.getValue("name");
/*  65 */     String logview = attributes.getValue("logview");
/*  66 */     String count = attributes.getValue("count");
/*  67 */     String key = attributes.getValue("key");
/*  68 */     Service service = new Service(key);

/*  70 */     if (domain != null) {
/*  71 */       service.setDomain(domain);
    }
    
/*  74 */     if (name != null) {
/*  75 */       service.setName(name);
    }
    
    if (logview != null) {
/*  79 */       service.setLogview(logview);
    }
    
/*  82 */     if (count != null) {
/*  83 */       service.setCount(((Long)convert(Long.class, count, Long.valueOf(0L))).longValue());
    }
    
/*  86 */     return service;
  }

  
  public Url buildUrl(Attributes attributes) {
/*  91 */     String domain = attributes.getValue("domain");
/*  92 */     String name = attributes.getValue("name");
/*  93 */     String logview = attributes.getValue("logview");
/*  94 */     String count = attributes.getValue("count");
    String key = attributes.getValue("key");
/*  96 */     Url url = new Url(key);

/*  98 */     if (domain != null) {
/*  99 */       url.setDomain(domain);
    }
    
/* 102 */     if (name != null) {
/* 103 */       url.setName(name);
    }
    
/* 106 */     if (logview != null) {
/* 107 */       url.setLogview(logview);
    }
    
/* 110 */     if (count != null) {
/* 111 */       url.setCount(((Long)convert(Long.class, count, Long.valueOf(0L))).longValue());
    }
    
/* 114 */     return url;
  }

  
  protected <T> T convert(Class<T> type, String value, T defaultValue) {
/* 119 */     if (value == null || value.length() == 0) {
/* 120 */       return defaultValue;
    }
    
/* 123 */     if (type == Boolean.class || type == boolean.class)
/* 124 */       return (T)Boolean.valueOf(value); 
/* 125 */     if (type == Integer.class || type == int.class)
/* 126 */       return (T)Integer.valueOf(value); 
/* 127 */     if (type == Long.class || type == long.class)
/* 128 */       return (T)Long.valueOf(value); 
/* 129 */     if (type == Short.class || type == short.class)
/* 130 */       return (T)Short.valueOf(value); 
/* 131 */     if (type == Float.class || type == float.class)
/* 132 */       return (T)Float.valueOf(value); 
/* 133 */     if (type == Double.class || type == double.class)
/* 134 */       return (T)Double.valueOf(value); 
/* 135 */     if (type == Byte.class || type == byte.class)
/* 136 */       return (T)Byte.valueOf(value); 
/* 137 */     if (type == Character.class || type == char.class) {
/* 138 */       return (T)Character.valueOf(value.charAt(0));
    }
/* 140 */     return (T)value;
  }

  
  protected Date toDate(String str, String format, Date defaultValue) {
/* 145 */     if (str == null || str.length() == 0) {
/* 146 */       return defaultValue;
    }
    
    try {
/* 150 */       return (new SimpleDateFormat(format)).parse(str);
/* 151 */     } catch (ParseException e) {
/* 152 */       throw new RuntimeException(String.format("Unable to parse date(%s) in format(%s)!", new Object[] { str, format }), e);
    }
  }
}


/* Location:              /Users/hanfei/Documents/apache-tomcat-9.0.24/webapps/cat/WEB-INF/classes/!/com/dianping/cat/home/heavy/transform/DefaultSaxMaker.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       1.0.7
 */